package com.inspur.attendance.Dao;

import com.inspur.attendance.Entity.Overtime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public interface OverTimeDao extends JpaRepository<Overtime, Long> {


    public Overtime findTopById(Long id) throws Exception;

    @Query(nativeQuery = true, value = "select * from overtime where work_id = ?1")
    Page<Overtime> getMyOverTime(String id, Pageable pageable);

    @Query(nativeQuery = true,  value = "select * from overtime where work_id = ?1 and DATE_FORMAT(create_time,'%Y-%m-%d') = ?2 and (is_agree = 1 or is_agree =2)")
    List<Overtime> MyOvertimeRequest(String id, String date);

    @Query(nativeQuery = true, value = "select * from overtime where department = ?1 and DATE_FORMAT(create_time,'%Y-%m-%d') = ?2 and is_agree = 0")
    List<Overtime> findByDepartment(String departmentId, String date);
}
